package editor.project;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;

import javax.swing.JTree;
import javax.swing.tree.TreeNode;

/**
 * @author Mark Dessain
 */
@SuppressWarnings("serial")
public class ProjectTree extends JTree {
	
	public static Color selectedColor = new Color(179,178,177);
	public static Color selectedFontColor = new Color(255, 255, 255);
	
	/**
	 * @param root of tree
	 */
	public ProjectTree(TreeNode root)
	{
		super(root);
		setCellRenderer(new ProjectTreeRenderer());
	}

	/* (non-Javadoc)
	 * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
	 */
	@Override
	protected void paintComponent(Graphics g) 
	{
		 
		g.setColor(getBackground());
		g.fillRect(0, 0, getWidth(), getHeight());

		int fromRow = getRowForPath( getSelectionPath());
		if (fromRow != -1) {
			int toRow = fromRow + 1;
			Rectangle fromBounds = getRowBounds(fromRow);
			Rectangle toBounds = getRowBounds(toRow - 1);
			if (fromBounds != null && toBounds != null) {
				g.setColor(selectedColor);
				
				g.fillRect(0, fromBounds.y, getWidth(), toBounds.y - fromBounds.y + toBounds.height);
				g.setColor(selectedFontColor);
			}
		}

		// perform operation of superclass
		setOpaque(false); // trick not to paint background
		super.paintComponent(g);
		setOpaque(false);
	}
}


